from typing import List


class Solution:
    def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]:
        intervals.sort()

        ans = []
        for s, e in intervals:
            if e <= toBeRemoved[0]:
                ans.append([s, e])
            elif s < toBeRemoved[0] <= e <= toBeRemoved[1]:
                ans.append([s, toBeRemoved[0]])
            elif toBeRemoved[0] <= s <= e <= toBeRemoved[1]:
                pass
            elif toBeRemoved[0] <= s <= toBeRemoved[1] < e:
                ans.append([toBeRemoved[1], e])
            elif toBeRemoved[1] <= s:
                ans.append([s, e])
            elif s < toBeRemoved[0] <= toBeRemoved[1] < e:
                ans.append([s, toBeRemoved[0]])
                ans.append([toBeRemoved[1], e])
        return ans


if __name__ == "__main__":
    # [[0,1],[6,7]]
    print(Solution().removeInterval(intervals=[[0, 2], [3, 4], [5, 7]], toBeRemoved=[1, 6]))

    # [[0,2],[3,5]]
    print(Solution().removeInterval(intervals=[[0, 5]], toBeRemoved=[2, 3]))
